#include <iostream>
#include "loadlibraryproxy.h"
#include "dllbase.h"

#if !defined WINDOWS && !defined STATIC_PROJECT
#include <dlfcn.h>
#include "moduleloadlibrarylinux.h"
#elif defined WINDOWS && !defined STATIC_PROJECT
#include <windows.h>
#include "moduleloadlibrarywindows.h"
#endif

#ifdef STATIC_PROJECT
#include "testone.h"
#endif


int main(int argc, char** argv)
{
  dllbase   *ptest = NULL;
  std::string namespace_module;

#ifndef STATIC_PROJECT
  CLoadLibraryProxy *pproxy = CLoadLibraryProxy::CreateLoadLibraryProxy();

#ifndef WINDOWS
  pproxy->setModuleLoadLibrary(new CModuleLoadLibraryLinux());
#else
  pproxy->setModuleLoadLibrary(new CModuleLoadLibraryWindows());
#endif

  pproxy->setBasePathLibrary(pproxy->getexedir());


/* Load testone from testmodule */
  namespace_module = "testmodule";
  ptest = dynamic_cast<dllbase*>(pproxy->findObject(namespace_module, "testone"));
  
  if(ptest)
  {
    ptest->start(NULL);
    delete ptest; ptest = NULL;
  }
  else
  {
    std::cerr << pproxy->getModuleLoadLibrary()->getErrorDescription()  << std::endl;
    return -1;
  }


/* Load testone from testmodule.testmoduleone */
  namespace_module = "testmodule";
  namespace_module += pproxy->getNameSpaceSeparator();
  namespace_module += "testmoduleone";
  ptest = dynamic_cast<dllbase*>(pproxy->findObject(namespace_module, "testtwo"));

  if(ptest)
  {
    ptest->start(NULL);
    delete ptest; ptest = NULL;
  }
  else
  {
    std::cerr << pproxy->getModuleLoadLibrary()->getErrorDescription()  << std::endl;
    return -1;
  }





namespace_module = "testmodule";
  pproxy->deleteObject(namespace_module, "testone");

namespace_module = "testmodule";
namespace_module += pproxy->getNameSpaceSeparator();
namespace_module += "testmoduleone";

  pproxy->deleteObject(namespace_module, "testtwo");
#else
  ptest = new testmodule::testone();
  if(ptest)
  {
    ptest->start(NULL);
    delete ptest; ptest = NULL;
  }
  else
  {
    std::cerr << "pointer is NULL"  << std::endl;
    return -1;
  }
#endif
  return 0;
}

